﻿<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/sys_include.jsp"%>

<div style="padding: 4px;">
菜单名称
   <input id="s_sys_menu_name" name="s_sys_menu_name" type="text">&nbsp;&nbsp;
   <input id="s_sys_menu_btn" type="button" value="查　询">
</div>

<div style="padding: 4px;"><table id="sys_menu_grid"></table></div>
<div id="sys_menu_grid_page" style="padding: 4px;"></div>  


<div id="sys_menu_edit_window" title="菜单信息">
   <form id="sys_menu_edit_form" name="sys_menu_edit_form" method="POST">
      <div id="sys_menu_edit_errmsg"></div>

      <table width="100%">
         <tr>
            <td align="right">上级菜单</td>
            <td align="left">
               <ul id="sys_menu_edit_parent" class="easyui-combotree" style="width:320px;"></ul>
            </td>
         </tr>
         <tr>
            <td align="right">名称</td>
            <td align="left"><input id="sys_menu_edit_funcname" name="sys_menu_edit_funcname"/></td>
         </tr>
         <!--
         <tr>
            <td align="right">编号</td>
            <td align="left">
              <input id="sys_menu_edit_name" name="sys_menu_edit_name"/>
            </td>
         </tr>
         -->
         <tr>
            <td align="right">URL</td>
            <td align="left">
               <input id="sys_menu_edit_funcurl" name="sys_menu_edit_funcurl" style="width:320px;"/>
            </td>
         </tr>
         <tr>
            <td align="right">排序值</td>
            <td align="left"><input id="sys_menu_edit_seq" name="sys_menu_edit_seq"/></td>
         </tr>
         <tr>
            <td colspan="2" align="center">
            <input type="button" id="sys_menu_edit_submit_btn" value="提　交"/>&nbsp;&nbsp; 
            <input type="button" id="sys_menu_edit_close_btn" value="关　闭"/>
            </td>
         </tr>
      </table>
   </form>
</div>


<script>
   closeUIDialog('sys_menu_edit_window');

   jQuery("#sys_menu_grid").jqGrid(
   {
      caption: 
         '<a href="javascript:fun_sys_menu_add()"  class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-edit\'">新增</a>' +
         '<a href="javascript:fun_sys_menu_update()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-save\'">修改</a>' +
         '<a href="javascript:fun_sys_menu_delete()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-cancel\'">删除</a>',
      datatype: "json",
      url:'system/Menu/list.do',
      autowidth : true,
      hidegrid: false,
      forceFit: true,
      height : '100%',
      width: '100%',
      colNames:[ '编号', '名称', 'URL', '上级菜单id', '上级菜单', '排序值'],
      colModel:[
      {name:'funcId',index:'funcId', width:1,sorttype:'int',sortable:false},
      {name:'funcName',index:'funcName',width:160,sortable:false},
      {name:'funcUrl',index:'funcUrl',width:480,sortable:false},
      {name:'funcPid',index:'funcPid',width:1,sortable:false},
      {name:'funcPName',index:'funcPName',width:160,sortable:false},
      {name:'sortSeq',index:'sortSeq',width:60,sortable:false}
      ],
      multiselect: false,
      toolbar:[false,'top'],
      rowNum:10, 
      rowList:[5,10,20], 
      rownumbers: true,
      viewrecords: true, 
      sortname:  "funcId " ,
      sortorder: "asc",
      pager: '#sys_menu_grid_page', 
      jsonReader:
      {     
         root: 'dataRows',   
         repeatitems : false     
      }
   });
   jQuery("#sys_menu_grid").jqGrid('hideCol',['funcId', 'funcPid', 'sortSeq']);
       
   $('#sys_menu_edit_close_btn').unbind('click');
   $('#sys_menu_edit_close_btn').click(function()
   {
      closeUIDialog('sys_menu_edit_window');
   });

   var sys_menu_save_flag = true;
   
   $('#sys_menu_edit_submit_btn').unbind('click');
   $('#sys_menu_edit_submit_btn').click(function()
   {
      fun_sys_menu_submit();
   });
   
   function fun_sys_menu_add()
   {
      sys_menu_save_flag = true;
      $("#sys_menu_edit_form")[0].reset();
      $('#sys_menu_edit_errmsg').html('');
      openUIDialog('sys_menu_edit_window', true, 490, 210);
   }

   var sys_menu_select_row;
   
   function fun_sys_menu_update()
   {
      var gr = $("#sys_menu_grid").jqGrid('getGridParam', 'selrow');
      if(gr)
      {
         sys_menu_select_row = jQuery("#sys_menu_grid").jqGrid('getRowData', gr);
          
         sys_menu_save_flag = false;
         $("#sys_menu_edit_form")[0].reset();
         $('#sys_menu_edit_errmsg').html('');
         fun_sys_menu_load_data(sys_menu_select_row);
         openUIDialog('sys_menu_edit_window', true, 490, 210);
      }
      else
      {
         $.messager.alert('操作提示','请选择一条记录再操作！');
      }
   }

   function fun_sys_menu_load_data(rowData)
   {
      $("#sys_menu_edit_funcurl").val(rowData.funcUrl);
      $("#sys_menu_edit_funcname").val(rowData.funcName);
      $("#sys_menu_edit_parent").combotree('setValue', rowData.funcPid);
      $("#sys_menu_edit_seq").val(rowData.sortSeq);
   }

   
   function fun_sys_menu_submit()
   {
      var menuJson = new Object();
      menuJson.funcName = $('#sys_menu_edit_funcname').val();
      menuJson.funcUrl = $('#sys_menu_edit_funcurl').val();
      menuJson.funcPid = $('#sys_menu_edit_parent').combotree('getValue');
      menuJson.sortSeq = $('#sys_menu_edit_seq').val();
      menuJson.sort = 1;
      
      if(sys_menu_save_flag)
      {
          menuJson.id = '';
         
         $.ajax(
         {
             async : false,
            type : "POST",
            url : "system/Menu/save.do",
            data :
            {
               menuJson : JSON.stringify(menuJson)
            },
            dataType : "json",
            contentType : "application/x-www-form-urlencoded; charset=UTF-8",
            success : function(json)
            {
               if (json.success)
               {
                  $("#sys_menu_grid").trigger("reloadGrid");
                  $.messager.alert('操作提示', '操作成功！');
               }
               else
               {
                  $.messager.alert('操作提示', '操作失败，请重试！');
               }
            }
         });
      }
      else
      {
         menuJson.id = sys_menu_select_row.id;
         
         $.ajax(
         {
            async : false,
            type : "POST",
            url : "system/Menu/update.do",
            data :
            {
               menuJson : JSON.stringify(menuJson)
            },
            dataType : "json",
            contentType : "application/x-www-form-urlencoded; charset=UTF-8",
            success : function(json)
            {
               if (json.success)
               {
                  $("#sys_menu_grid").trigger("reloadGrid");
                  $.messager.alert('操作提示', '操作成功！');
               }
               else
               {
                  $.messager.alert('操作提示', '操作失败，请重试！');
               }
            }
         });
      }
      
      closeUIDialog('sys_menu_edit_window');
   }

   function fun_sys_menu_delete()
   {
      var gr = $("#sys_menu_grid").jqGrid('getGridParam', 'selrow');
      if(gr)
      {
         $.messager.confirm('删除提示','您确认要删除?',function(r)
         {   
            if(r)
            {
               fun_sys_menu_del(gr);
            }
         });
      }
      else
      {
         $.messager.alert('操作提示','请先选择一条记录再进行操作！');
      }
   }

   function fun_sys_menu_del(menuids)
   {
      $.ajax(
      {
          async : false,
         type : "POST",
         url : "system/Menu/delete.do",
         dataType : "json",
         data :
         {
            ids : menuids
         },
         success : function(json)
         {
            if (json.success)
            {
               $("#sys_menu_grid").trigger("reloadGrid");
               $.messager.alert('操作提示', '操作成功！');
            }
            else
            {
               $.messager.alert('操作提示', '操作失败，请重试！');
            }
         }
      });
   }
    
   $('#s_sys_menu_btn').unbind('click');
   $('#s_sys_menu_btn').click(function()
   {
      var s_name=$('#s_sys_menu_name').val();
      
      $("#sys_menu_grid").setGridParam(
      {
          url:'system/Menu/list.do',
          mtype: 'post',
          postData:{'s_description':s_name}
      });
      
      $("#sys_menu_grid").trigger("reloadGrid");
   });


   $(function()
   {
      $('#sys_menu_edit_parent').combotree({
         valueField: 'id',  
         textField: 'text'
      });

      var req_param = new Object();
      req_param.user_id = '0';
      
      $.ajax(
      {
         type : "POST",
         async : true,
         url : "system/Menu/getMenuData.do",
         dataType : "json",
         data :
         {
            req_param : JSON.stringify(req_param)
         },
         contentType : "application/x-www-form-urlencoded; charset=UTF-8",
         success : function(json)
         {
            if (json.success)
            {
               $('#sys_menu_edit_parent').combotree('loadData', json.msg);
            }
            else
            {
               $.messager.alert('操作提示','加载菜单数据出错，请重试！');
            }
         }
      });
   });
   
</script>
